<template>
    <h2>用户投资</h2>
    <table class="table table-border" border="1" cellpadding="0" cellspacing="0">
        <tr>
            <td>投资项目名称</td>
            <td>{{ info.IName }}</td>
        </tr>
        <tr>
            <td>投资项目总金额</td>
            <td>{{ info.IMoney }}</td>
        </tr>
        <tr>
            <td>已投资额度</td>
            <td>{{ info.StateMoney }}</td>
        </tr>
        <tr>
            <td>剩余投资额度</td>
            <td>{{ info.EndMoney }}</td>
        </tr>
        <tr>
            <td>投资金额</td>
            <td><input type="text" v-model="smoney"></td>
        </tr>
        <tr>
            <td colspan="2"><input type="button" value="提交" @click="add"></td>
        </tr>
    </table>
</template>
<script setup lang="ts">
import axios from 'axios'
import { ref ,onMounted} from 'vue';
import { useRoute,useRouter } from 'vue-router';
import {useuseStore} from '../../store/index.ts'
const router=useRouter()
const store=useuseStore()
const route = useRoute();
const info=ref({
    IName:"",
    IMoney:0,
    StateMoney:0,
    EndMoney:0,
    ISum:0
})
onMounted(()=>{
    show()
})
const smoney=ref(0)
const show=()=>{
    axios({
        url:"https://localhost:44394/api/InverstController/Find",
        params:{
            id:route.params.id
        },
        method:"get"
    })
    .then(res=>{
        info.value=res.data
    })
}
const add=()=>{
    axios({
        url:"https://localhost:44394/api/InverstController/UserInverstADD",
        data:{
            Uid:store.someState,
            IId:route.params.id,
            UMoney:smoney.value
        },
        method:"post"
    })
    .then(res=>{
        if(res.data>0){
            alert('添加成功')
            router.push("/userinverstshow")
        }else{
            alert('添加失败')
        }
    })
}
</script>